<nb-card [nbSpinner]="loading" nbSpinnerStatus="primary" nbSpinnerSize="large">
	<nb-card-header class="d-flex flex-column pb-0">
		<div class="card-header-title">
			<h4>
				<ngx-header-title>
					{{ 'TIME_OFF_PAGE.HEADER' | translate }}
				</ngx-header-title>
			</h4>
			<ng-template ngxPermissionsOnly="POLICY_VIEW">
				<button
					(click)="openTimeOffSettings()"
					nbButton
					status="basic"
					class="action p-2"
				>
					<i class="fas fa-cog"></i>
				</button>
			</ng-template>
		</div>
		<div class="align-self-end d-flex align-items-center">
			<ngx-gauzy-button-action
				[buttonTemplate]="actionButtons"
				[buttonTemplateVisible]="visibleButton"
				[hasLayoutSelector]="false"
				[isDisable]="!isRecordSelected"
			></ngx-gauzy-button-action>
			<nb-toggle
				[(ngModel)]="displayHolidays"
				(checkedChange)="changeDisplayHolidays($event)"
				class="custom-toggle mr-3 ml-3"
				status="primary"
				checked
			>
				{{ 'TIME_OFF_PAGE.DISPLAY_HOLIDAYS' | translate }}
			</nb-toggle>
			<ga-layout-selector
				[componentName]="viewComponentName"
			></ga-layout-selector>
		</div>
	</nb-card-header>
	<nb-card-body>
		<ng-template [ngIf]="showFilter">
			<div class="row mb-3 justify-content-end">
				<div class="filter">
					<nb-radio-group
						class="align-center radio-group mr-5"
						[(ngModel)]="selectedStatus"
						(ngModelChange)="detectStatusChange($event)"
					>
						<nb-radio
							class="d-flex"
							*ngFor="let status of timeOffStatuses"
							[value]="status"
						>
							{{ 'TIME_OFF_PAGE.STATUSES.' + status | translate }}
						</nb-radio>
					</nb-radio-group>
					<nb-toggle
						[(ngModel)]="includeArchived"
						(checkedChange)="changeIncludeArchived($event)"
						status="warning"
						class="my-auto align-center"
					>
						{{ 'FORM.CHECKBOXES.INCLUDE_ARCHIVED' | translate }}
					</nb-toggle>
				</div>
			</div>
		</ng-template>
		<ng-template
			[ngIf]="dataLayoutStyle === componentLayoutStyleEnum.TABLE"
			[ngIfElse]="gridLayout"
		>
			<div class="table-scroll-container custom-table">
				<angular2-smart-table
					class="time-off-table"
					style="cursor: pointer"
					[settings]="settingsSmartTable"
					[source]="sourceSmartTable"
					(userRowSelect)="selectRecord($event)"
					#timeOffTable
				></angular2-smart-table>
			</div>
			<ng-container *ngIf="smartTableSource">
				<ngx-pagination
					[source]="smartTableSource"
				></ngx-pagination>
			</ng-container>
		</ng-template>
		<ng-template #gridLayout>
			<div class="custom-grid">
				<ga-card-grid
					[totalItems]="pagination?.totalItems"
					(onSelectedItem)="selectRecord($event)"
					(scroll)="onScroll()"
					[settings]="settingsSmartTable"
					[source]="timeOffs"
				></ga-card-grid>
			</div>
		</ng-template>
	</nb-card-body>
</nb-card>

<ng-template #actionButtons let-selectedItem="selectedItem">
	<ng-template ngxPermissionsOnly="TIME_OFF_EDIT">
		<div class="btn-group actions">
			<ng-container>
				<button
					(click)="updateTimeOffRecord()"
					*ngIf="!selectedTimeOffRecord?.isHoliday"
					#editButton
					nbButton
					status="basic"
					size="small"
					class="action primary"
				>
					<nb-icon class="mr-1" icon="edit-outline"></nb-icon>
					{{ 'BUTTONS.EDIT' | translate }}
				</button>
				<button
					(click)="deleteRequest(selectedItem)"
					#deleteButton
					nbButton
					status="basic"
					size="small"
					class="action"
					[nbTooltip]="'BUTTONS.DELETE' | translate"
				>
					<nb-icon status="danger" icon="trash-2-outline"></nb-icon>
				</button>
				<button
					nbButton
					(click)="showAdditionalActions()"
					*ngIf="!showActions"
					status="basic"
					size="small"
					class="action"
				>
					<nb-icon
						icon="more-horizontal-outline"
						cursor="pointer"
					></nb-icon>
				</button>
			</ng-container>
		</div>
	</ng-template>
	<ng-template [ngIf]="showActions">
		<div class="btn-group actions ml-2">
			<ng-container *ngTemplateOutlet="additionalActions"> </ng-container>
		</div>
	</ng-template>
</ng-template>
<ng-template #visibleButton>
	<button
		nbButton
		size="small"
		class="action"
		status="success"
		(click)="requestDaysOff()"
	>
		<nb-icon class="mr-1" icon="calendar-outline"></nb-icon>
		{{ 'BUTTONS.ADD' | translate }}
	</button>
	<button
		nbButton
		size="small"
		status="basic"
		class="action info"
		(click)="addHolidays()"
	>
		<nb-icon class="mr-1" icon="plus-outline"></nb-icon>
		{{ 'TIME_OFF_PAGE.ADD_HOLIDAYS' | translate }}
	</button>
	<button
		(click)="showFilter = !showFilter"
		nbButton
		status="basic"
		size="small"
		class="action primary"
	>
		<nb-icon icon="funnel-outline"></nb-icon>
		{{ 'BUTTONS.FILTER' | translate }}
	</button>
</ng-template>
<ng-template #additionalActions>
	<button
		(click)="approveDaysOff(selectedItem)"
		nbButton
		status="success"
		size="small"
		class="action"
	>
		<nb-icon class="mr-1" icon="checkmark-circle-outline"></nb-icon>
		{{ 'BUTTONS.APPROVE' | translate }}
	</button>
	<button
		(click)="denyDaysOff(selectedItem)"
		nbButton
		status="warning"
		size="small"
		class="action"
	>
		<nb-icon class="mr-1" icon="close-outline"></nb-icon>
		{{ 'BUTTONS.DENY' | translate }}
	</button>
	<button
		nbButton
		(click)="archive()"
		#archiveButton
		status="basic"
		size="small"
		class="action secondary"
		[disabled]="
			selectedTimeOffRecord ? selectedTimeOffRecord.isArchived : true
		"
	>
		<nb-icon class="mr-1" icon="archive-outline"></nb-icon
		>{{ 'BUTTONS.ARCHIVE' | translate }}
	</button>
	<button
		nbButton
		(click)="showAdditionalActions()"
		status="basic"
		size="small"
		class="action"
	>
		<nb-icon icon="close-outline" cursor="pointer"></nb-icon>
	</button>
</ng-template>
